<?php
/**
 * Lists all the courses a student is currently registered for and allows deletions
 */
?>
<html>
<head>
<?php
require_once '../dbms_university_courses_mvc/Model/model_require_once.php';
?>
</head>
<body>
<h1>Fall 2009 Courses</h1>
<?php
/* @var $profile Profile */
$profile = Profile::constructFrom_profile_id ( $_SESSION ['profile_id'] );
/* @var $student Student */
$students = Student::getStudents_by_profile_id ( $_SESSION ['profile_id'] );
if (count ( $students ) == 1) {
	$student = $students [0]; //profiles only
} else {
	?><script type="text/javascript">alert("Database Consistency Error: students retrieved with profile <?php
	echo $_SESSION ['profile_id']?> returned <?php
	count ( $students )?> students");</script><?php
}

$student_course_registrations = StudentCourseRegistration::getStudentCourseRegistrations_by_student_id ( $student->get_student_id () );

?>
<script type="text/javascript">
	var profile = new Profile(<?php
	echo json_encode ( $profile );
	?>);
</script>
<table>
	<tr>
		<th>Course Name</th>
		<th>Instructor</th>
		<th>Department</th>
		<th>Credits</th>
		<th>Classroom</th>
		<th>Periods</th>
	</tr>
<?php
/* @var $student_course_registration StudentCourseRegistration */
foreach ( $student_course_registrations as $student_course_registration ) {
	/* @var $course Course */
	$course = Course::constructFrom_course_id ( $student_course_registration->get_course_id () );
	/* @var $term Term */
	$term = Term::constructFrom_term_id ( $course->get_term_id () );
	if ($term->get_year () == 2009 && strtolower ( $term->get_term () ) == "fall") {
		?>
	<tr>
		<td><?php
		echo $course->get_course_name ();
		?></td>
		<td><?php
		if ($course->get_instructor_id ()) {
			/* @var $instructor Instructor */
			$instructor = Instructor::constructFrom_instructor_id ( $course->get_instructor_id () );
			/* @var $instructor_profile Profile */
			$instructor_profile = Profile::constructFrom_profile_id ( $instructor->get_profile_id () );
			echo $instructor_profile->get_first_name () . " " . $instructor_profile->get_last_name ();
		}
		?></td>
		<td><?php
		/* @var $department Department */
		$department = Department::constructFrom_department_id ( $course->get_department_id () );
		echo $department->get_department_name ();
		?></td>

		<td><?php
		echo $course->get_credits ();
		?></td>
		<td><?php
		echo $course->get_classroom_id ();
		?></td>
		<td>
		<input type="button"
			onclick="openDialog('views/course_periods.php?course_id=<?php echo $course->get_course_id();?>');"
			value="Periods"
		/>
		</td>
		<td><script type="text/javascript">
	var StudentCourseRegistration<?php
		echo $student_course_registration->get_registration_id ();
		?> = new StudentCourseRegistration(<?php
		echo json_encode ( $student_course_registration );
		?>);
			</script> <input type="button"
			title="Remove this course from my schedule"
			onclick="StudentCourseRegistration<?php
		echo $student_course_registration->get_registration_id ();
		?>.deleteMeFromDatabase(refreshPage);"
			value="Remove"
		/></td>
	</tr>
	<?php
	}
}
?>
</table>
</body>
</html>